home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / menu_dvd.swf / scripts / __Packages / HtmlTreeCellRenderer.as < prev    next >
Text File  |  2007-11-07  |  3KB  |  104 lines

  1. class HtmlTreeCellRenderer extends mx.core.UIComponent
  2. {
  3.    static var style_sheet = null;
  4.    static var USE_EMBEDDED_FONT = true;
  5.    static var ADD_DOT = false;
  6.    static var SPAN_BEFORE = "<span class=\'rowText\'>";
  7.    static var SPAN_AFTER = "</span>";
  8.    var previousLabel = null;
  9.    function HtmlTreeCellRenderer()
  10.    {
  11.       super();
  12.       if(HtmlTreeCellRenderer.ARRAY_ABBREVIAZIONI == undefined)
  13.       {
  14.          HtmlTreeCellRenderer.ARRAY_ABBREVIAZIONI = Array(" ill"," tab"," tabb"," fig"," cart"," segg"," diagr"," col"," mus");
  15.       }
  16.    }
  17.    function createChildren(Void)
  18.    {
  19.       if(HtmlTreeCellRenderer.CssUrl != undefined && HtmlTreeCellRenderer.style_sheet == null)
  20.       {
  21.          HtmlTreeCellRenderer.style_sheet = new TextField.StyleSheet();
  22.          HtmlTreeCellRenderer.style_sheet.load(HtmlTreeCellRenderer.CssUrl);
  23.       }
  24.       if(this.htmlComponent == undefined)
  25.       {
  26.          this.createLabel("htmlComponent",1);
  27.       }
  28.       this.htmlComponent.embedFonts = HtmlTreeCellRenderer.USE_EMBEDDED_FONT;
  29.       this.htmlComponent.html = true;
  30.       this.htmlComponent.border = false;
  31.       this.htmlComponent.multiline = false;
  32.       this.htmlComponent.wordWrap = false;
  33.       this.htmlComponent.selectable = false;
  34.       this.htmlComponent.background = false;
  35.       this.htmlComponent.styleSheet = HtmlTreeCellRenderer.style_sheet;
  36.       this.size();
  37.    }
  38.    function size(Void)
  39.    {
  40.       this.htmlComponent.setSize(this.__width - 2,this.__height);
  41.    }
  42.    function setValue(str, item, sel)
  43.    {
  44.       if(item == undefined)
  45.       {
  46.          this.htmlComponent.htmlText = this.HtmlFunction(str,"");
  47.          this.previousLabel = null;
  48.          return undefined;
  49.       }
  50.       var columnIndex = this.columnIndex;
  51.       var columnName = this.getDataLabel();
  52.       var htmlFunction = this.listOwner.getColumnAt(columnIndex).htmlFunction;
  53.       var label = this.HtmlFunction(str,columnName);
  54.       if(label != undefined)
  55.       {
  56.          if(label != this.previousLabel)
  57.          {
  58.             this.htmlComponent.htmlText = this.previousLabel = HtmlTreeCellRenderer.SPAN_BEFORE + label + HtmlTreeCellRenderer.SPAN_AFTER;
  59.          }
  60.       }
  61.       else
  62.       {
  63.          this.htmlComponent.htmlText = "";
  64.       }
  65.    }
  66.    function getPreferredHeight(Void)
  67.    {
  68.       if(this.owner == undefined)
  69.       {
  70.          return 18;
  71.       }
  72.       return this.owner.__height;
  73.    }
  74.    function HtmlFunction(inLabel, columnName)
  75.    {
  76.       var outV = inLabel;
  77.       outV = outV.split("<sub>").join("<sub>");
  78.       outV = outV.split("</sub>").join("</sub>");
  79.       outV = outV.split("<sup>").join("<sup>");
  80.       outV = outV.split("</sup>").join("</sup>");
  81.       outV = outV.split("\\[").join("");
  82.       outV = outV.split("\\]").join("");
  83.       if(outV.indexOf("<sup>") >= 0 || outV.indexOf("<sub>") >= 0)
  84.       {
  85.          outV = StringUtils.subSupFromHTML(outV);
  86.       }
  87.       if(HtmlTreeCellRenderer.ADD_DOT)
  88.       {
  89.          var len = outV.length;
  90.          var i = 0;
  91.          while(i < HtmlTreeCellRenderer.ARRAY_ABBREVIAZIONI.length)
  92.          {
  93.             if(outV.lastIndexOf(HtmlTreeCellRenderer.ARRAY_ABBREVIAZIONI[i]) == len - HtmlTreeCellRenderer.ARRAY_ABBREVIAZIONI[i].length)
  94.             {
  95.                outV += ".";
  96.                break;
  97.             }
  98.             i++;
  99.          }
  100.       }
  101.       return outV;
  102.    }
  103. }
  104.